# Maintainer: crapStone <crapstone01@gmail.com>
pkgname=rbw
pkgver=1.4.3
pkgrel=0
pkgdesc="Unofficial command line client for Bitwarden."
url="https://git.tozt.net/rbw"
arch="all !s390x !riscv64 !ppc64le" # limited by cargo, dependency ring does not support ppc64le
license="MIT"
depends="pinentry"
makedepends="rust cargo"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://git.tozt.net/rbw/snapshot/rbw-$pkgver.tar.gz"
export CARGO_HOME="$srcdir"/cargo

# Reduce size of the binaries.
# 9.1M -> 4.3M
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
export CARGO_PROFILE_RELEASE_LTO="true"
export CARGO_PROFILE_RELEASE_OPT_LEVEL="s"
export CARGO_PROFILE_RELEASE_PANIC="abort"

prepare() {
	default_prepare
	cargo fetch --locked
}

build() {
	cargo build --frozen --release

	target/release/rbw gen-completions bash > rbw.bash
	target/release/rbw gen-completions fish > rbw.fish
	target/release/rbw gen-completions zsh > _rbw
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 target/release/rbw "$pkgdir"/usr/bin/rbw
	install -Dm755 target/release/rbw-agent "$pkgdir"/usr/bin/rbw-agent

	install -Dm644 rbw.bash \
		"$pkgdir"/usr/share/bash-completion/completions/rbw
	install -Dm644 rbw.fish \
		"$pkgdir"/usr/share/fish/completions/rbw.fish
	install -Dm644 _rbw \
		"$pkgdir"/usr/share/zsh/site-functions/_rbw
}

sha512sums="
98b1d17fa31a753a47673e34ed740785992d660c35827975a6c89638e479aeca381af0c83c43769179a3530f24f853fbab41e63eccfbf08902e7b8738703db2d  rbw-1.4.3.tar.gz
"
